<!DOCTYPE HTML>
<html>
<head>
<title>If[Not]Exist | AutoHotkey</title>
<meta name="description" content="The IfExist and IfNotExist statements check for the existence of a file or folder." />
<meta name="ahk:equiv-v2" content="commands/FileExist.htm" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<link href="../static/theme.css" rel="stylesheet" type="text/css" />
<script src="../static/content.js" type="text/javascript"></script>
<script type="text/javascript">$(function(){0<=window.navigator.userAgent.toLowerCase().indexOf("ucbrowser")&&CaoNiMaDeUc()})</script>
</head>
<body>

<h1>If[Not]Exist</h1>

<p>检查文件或文件夹是否存在.</p>
<p class="warning"><strong>不推荐:</strong> 这些命令不推荐在新脚本中使用. 使用 <a href="FileExist.htm">FileExist</a> 函数代替.</p>

<pre class="Syntax">
<span class="func">IfExist</span>, FilePattern
<span class="func">IfNotExist</span>, FilePattern
</pre>
<h2>参数</h2>
<dl>

  <dt>FilePattern</dt>
  <dd><p>需检查的路径, 文件名或文件模式. 如果未指定绝对路径, 则假定 <em>FilePattern</em> 在 <a href="../Variables.htm#WorkingDir">%A_WorkingDir%</a> 中.</p></dd>

</dl>

<h2>相关</h2>
<p><a href="FileExist.htm">FileExist()</a>, <a href="Block.htm">区块</a>, <a href="Else.htm">Else</a>, <a href="LoopFile.htm">文件循环</a></p>
<h2>示例</h2>
<div class="ex" id="ExBasic">
<p><a href="#ExBasic">#1</a></p>
<pre>IfExist, D:\
    MsgBox, The drive exists.
IfExist, D:\Docs\*.txt
    MsgBox, At least one .txt file exists.
IfNotExist, C:\Temp\FlagFile.txt
    MsgBox, The target file does not exist.</pre>
</div>

</body>
</html>